package com.youlu.campus.admin.tencentcloud.utils;

import com.tencentcloudapi.clb.v20180317.ClbClient;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.cvm.v20170312.CvmClient;
import com.tencentcloudapi.dnspod.v20210323.DnspodClient;
import com.youlu.campus.admin.tencentcloud.entity.TencentCloudConfig;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * 腾讯云连接 工具类
 *
 * @Description: TencentCloudClientUtil
 * @Date 2025/10/21
 * @module TencentCloudClientUtil
 * @author: su
 */
@Slf4j
public class TencentCloudClientUtil {

    private TencentCloudClientUtil() {
    }

    /**
     * 初始化负载均衡 客户端
     *
     * @return
     */
    public static ClbClient createClbClient(TencentCloudConfig config) {
        Credential cred = new Credential(config.getSecretId(), config.getSecretKey());
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setConnTimeout(30);      // 连接超时30秒
        httpProfile.setEndpoint(config.getEndpoint()); // API端点
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        clientProfile.setSignMethod("HmacSHA256"); // 签名算法
        clientProfile.setDebug(true);              // 开启调试日志
        return new ClbClient(cred, "ap-beijing", clientProfile); // 替换为实际地域
    }

    /**
     * 初始化DNS 客户端
     *
     * @return
     */
    public static DnspodClient createDnsClient(TencentCloudConfig config) {
        Credential cred = new Credential(config.getSecretId(), config.getSecretKey());
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setConnTimeout(30);      // 连接超时30秒
        httpProfile.setEndpoint(config.getEndpoint()); // API端点
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        clientProfile.setSignMethod("HmacSHA256"); // 签名算法
        clientProfile.setDebug(true);              // 开启调试日志
        return new DnspodClient(cred, "ap-beijing", clientProfile);
    }

    /**
     * 初始化DNS 客户端
     *
     * @return
     */
    public static CvmClient createInstanceClient(TencentCloudConfig config) {
        Credential cred = new Credential(config.getSecretId(), config.getSecretKey());
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setConnTimeout(30);      // 连接超时30秒
        httpProfile.setEndpoint(config.getEndpoint()); // API端点
        // 配置客户端（签名算法、调试模式等）
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        clientProfile.setSignMethod("HmacSHA256"); // 签名算法
        clientProfile.setDebug(true);              // 开启调试日志
        // 实例化客户端
        return new CvmClient(cred, "ap-beijing", clientProfile);
    }

}
